﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Data.Objects.DataClasses;
using System.Data.Services.Common;
using ADONETDataServicesExtension;
using ADONETDataServicesExtension.BLLUtils;

namespace BLL
{
    [DataServiceKey("Id")]
    [EFEntityType(EntitySetName="Contacts")]
    public abstract class Contact : BaseEntityType<EFEntities.Contact>, IEntity
    {
        public Contact() :
            base(() => GetNewEFContact())
        {
        }
        public Contact(EFEntities.Contact contact)
            : base(contact)
        {
        }

        protected abstract EFEntities.Contact GetNewEFContact();

        [EFEntityProperty]
        public Guid Id
        {
            get { return EFEntity.Id; }
            set { EFEntity.Id = value; }
        }

        [EFEntityProperty]
        public virtual string LastName
        {
            get { return EFEntity.LastName; }
            set { EFEntity.LastName = value; }
        }

        [EFEntityProperty]
        public virtual string FirstName
        {
            get { return EFEntity.FirstName; }
            set { EFEntity.FirstName = value; }
        }

        [EFEntityProperty]
        public virtual string Title
        {
            get { return EFEntity.Title; }
            set { EFEntity.Title = value; }
        }

        private Information _informations;
        [EFEntityProperty]
        public Information Informations
        {
            get
            {
                if (_informations == null)
                    _informations = new Information(EFEntity.Informations);
                return _informations;
            }
            set
            {
                _informations = value;
                EFEntity.Informations = value.EFInformation;
            }
        }

        [EFEntityProperty]
        public virtual string Mobile
        {
            get { return EFEntity.Mobile; }
            set { EFEntity.Mobile = value; }
        }

        [EFEntityProperty]
        public virtual string EMail
        {
            get { return EFEntity.EMail; }
            set { EFEntity.EMail = value; }
        }

        [EFEntityProperty]
        public virtual string MsnAddress
        {
            get { return EFEntity.MsnAddress; }
            set { EFEntity.MsnAddress = value; }
        }

        EntityObject IEntity.EFEntity
        {
            get { return EFEntity; }
        }
    }
}
